package com.example.springsercurityservice.service;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class MyUserDetailService implements UserDetailsService , InitializingBean {

    private Map<String,User> map=new HashMap<>();

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return map.get(username);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        User wxx = new User("wxx", "{noop}123", Arrays.asList());
        User liujing = new User("liujing", "{noop}1234", Arrays.asList());

        map.put("wxx",wxx);
        map.put("liujing",liujing);
    }
}
